<template>
  <span class="avatar">
    <img
      :src="error ? errorSrc : src || errorSrc"
      class="pic"
      @error="error = true"
    >
  </span>
</template>

<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
  props: {
    src: {
      type: String,
      default: '',
    },
    errorSrc: {
      type: String,
      default: require('assets/mine/default-avatar.png'),
    },
  },
  data () {
    return {
      error: false,
    }
  },
})
</script>

<style lang="scss" scoped>
.avatar {
  display: inline-block;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  text-align: center;
  vertical-align: middle;
  .pic {
    display: block;
    width: 100%;
    height: 100%;
  }
}
</style>
